package com.design.fitment.view;

/**
 * Created by 娇哥 on 2016/1/13.
 */

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.design.fitment.R;
import com.design.fitment.app.MyApplication;
import com.design.fitment.entity.CasesDtail;
import com.design.fitment.util.DesignNetworkUtil;
import com.design.fitment.util.RequestDataCallback;
import com.google.gson.Gson;
import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.ArrayList;
import java.util.List;

/**
 * 头部组合控件
 */
public class CasesDtailHeaderView extends FrameLayout {

    private Context context;
    private List<CasesDtail.DataEntity> mList = new ArrayList<>();
    @ViewInject(R.id.iv_cases_detail)
    private ImageView ivCaseDetail;
    @ViewInject(R.id.tv1_cases_detail)
    private TextView tv1CasesDetail;
    @ViewInject(R.id.tv2_cases_detail)
    private TextView tv2CasesDetail;
    @ViewInject(R.id.iv_cases_detail_header_round)
    private RoundImageView ivCasesDetailHeaderRound;
    @ViewInject(R.id.tv3_cases_detail)
    private TextView tv3CasesDetail;
    @ViewInject(R.id.tv4_cases_detail)
    private TextView tv4CasesDetail;
    @ViewInject(R.id.iv_cases_detail_call)
    private ImageView ivCasesDetailCall;
    @ViewInject(R.id.tv_detail_content)
    private TextView tvCasesContent;
    private ImageLoader imageLoader;
    private DisplayImageOptions options;
    private int casesId;
    public CasesDtailHeaderView(Context context,int casesId) {
        super(context);
        this.context = context;
        this.casesId = casesId;
        initViews();

    }
    private void initViews() {
        View view =  LayoutInflater.from(context).inflate(R.layout.cases_detail, this, true);
        ViewUtils.inject(this, view);
        imageLoader = MyApplication.getApp().getImageLoader();
        options = MyApplication.getApp().getImageOptions();

    }

    public  void loadBanner(){
        DesignNetworkUtil.getInstance().getCasesDetail(new RequestDataCallback() {
            @Override
            public void onSuccess(String response) {
                Gson gson = new Gson();
                CasesDtail detail = gson.fromJson(response, CasesDtail.class);
                if (detail != null) {
                    CasesDtail.DataEntity data = detail.getData();
                    imageLoader.displayImage(data.getImgUrl(), ivCaseDetail, options);
                    imageLoader.displayImage(data.getFacePic(), ivCasesDetailHeaderRound, options);
                    tv1CasesDetail.setText(data.getName());
                    tv2CasesDetail.setText(data.getAreaName() + " " + data.getSpaceName() + " " + data.getStyleName());
                    tv3CasesDetail.setText("设计师:" + data.getNick());
                    tv4CasesDetail.setText("设计费用:" + data.getFeeRand());
                    tvCasesContent.setText(data.getComment());


                }

            }

            @Override
            public void onFailure(HttpException error) {

            }
        }, casesId);
    }


}
